<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>验证码</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/1.10.0/jquery.js"></script>
</head>
<body>
    <div id="yanzheng">
        <h1>图像验证码</h1>
        <img src="http://localhost:8080/getimg" id="images" onclick="replaceImg()">
        <br>
        <input size="20" placeholder="请输入验证码" id="input" required="true"/>
        <br>
        <button onclick="doYanzheng()" >验证</button>
        <br>
    </div>

</body>

<script>
    function replaceImg(){
        let x = document.getElementById("images").src="http://localhost:8080/getimg";
    };
    function doYanzheng() {
        var data=$("#input").val();
        console.log("data",data);
        if (data==''){
            alert("请输入");
        }else{
            $.ajax(
                {
                    type:"get",
                    url:"login",
                    data:"code="+data, //get请求的params参数
                    async:false,  //使用ajax同步提交数据
                    success:function (response) {
                        if (response==false){
                            alert("登录失败");
                        }else  if (response==true){
                            // alert("登录成功,,,1秒后跳转到系统主页");
                            setTimeout(window.location.href="/admin/main",1000);
                        }else{
                            alert("登录失败，请联系管理员....");
                        }
                    }
                }
            );
        }
    }

</script>

